<?php
namespace App\Repositories\Admin;

use App\Models\Admin\CompanyStaffsModel;
use App\Repositories\BaseRepository;

class ComStaffsRepository extends BaseRepository
{
    protected $repository;

    public function __construct()
    {
        $this->repository = new CompanyStaffsModel();
    }

    public function setAdd($data)
    {
        return $this->repository->insertGetId($data);
    }

    public function setModify($data,$id)
    {
        return $this->repository->where('id',$id)
            ->update($data);
    }

    public function setModifyByCid($data,$cid)
    {
        return $this->repository->where('cid',$cid)
            ->update($data);
    }

    public function getShowOne($id)
    {
        return $this->repository->where('id',$id)->first();
    }

    public function getShowByCid($cid)
    {
        return $this->repository->where('cid',$cid)->get();
    }

    public function getCidByUid($uid)
    {
        $model = $this->repository
            ->where('staff',$uid)
            ->where('is_use',2)
            ->first();
        return $model ? $model->cid : 0;
    }

    public function getShowByGroup($group)
    {
        return $this->repository->where('group',$group)->get();
    }
}